package com.fastbee.sip.server;

import com.fastbee.sip.model.VideoSessionInfo;
import com.fastbee.sip.util.SipUtil;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class VideoSessionManager {
    private final ConcurrentHashMap<String, VideoSessionInfo> sessionMap = new ConcurrentHashMap<>();
    public static Map<String, Long> CSEQCACHE = new ConcurrentHashMap<>();

    public String createPlaySsrc(String domain){
        return SipUtil.getPlaySsrc(domain);
    }

    public String createPlayBackSsrc(String domain){
        return SipUtil.getPlayBackSsrc(domain);
    }

    public void put(String ssrc, VideoSessionInfo transaction){
        sessionMap.put(ssrc, transaction);
    }

    public VideoSessionInfo get(String ssrc){
        return sessionMap.get(ssrc);
    }

    public void remove(String ssrc) {
        sessionMap.remove(ssrc);
        SipUtil.releaseSsrc(ssrc);
    }
}
